<?php

namespace App\Console\Commands;

use App\Facades\SamLogFacade;
use App\Models\UserCertOcr;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Exception;

class CheckCertValid extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'check:cert_valid';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'check cert is not valid today';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $date = date('Y-m-d');
        SamLogFacade::debug(Carbon::now()."检查{$date}的身份证");
        try{
            UserCertOcr::whereDate('valid_date_end', $date)
                ->update(['is_valid'=>0]);
        }catch (Exception $exception){
            SamLogFacade::debug('error',"身份证检查有效期错误：".$exception->getMessage());
        }
    }
}
